<template>
  <a-modal
    title="绑定手机号"
    :visible="visible"
    :centered="true"
    :bodyStyle="{textAlign:'center',width:'596px',minHeight:'480px'}"
    :afterClose="close"
    :width="596"
    :footer="null"
    :zIndex="1001"
  >
    <div>
      <div class="tits">
        <img class="logo" src="https://oss.itemplay.com/logozz.png">
      </div>
      <a-row type="flex" class="forms">
        <a-col :span="24" class="fitem">
          <a-col :span="6">地区</a-col>
          <a-col :span="16">
            <a-select v-model="qcode">
              <a-select-option
                :value="item.prefix + ',' + index"
                v-for="(item,index) in qcodeArr"
                :key="item.id"
              >+{{item.prefix}} {{item.country}}</a-select-option>
            </a-select>
          </a-col>
        </a-col>
        <a-col :span="24" class="fitem">
          <a-col :span="6">手机号</a-col>
          <a-col :span="16">
            <a-input placeholder="请输入手机号" v-model="phone"></a-input>
          </a-col>
        </a-col>
        <a-col :span="24" class="fitem">
          <a-col :span="16">
            <a-input placeholder="请输入短信验证码" v-model="code"></a-input>
          </a-col>
          <a-col :span="6">
            <a-button class="yzbtn" v-if="yzSoft">{{this.yzNum}}</a-button>
            <a-button class="yzbtn" @click="onYzbtn" v-else>获取验证码</a-button>
          </a-col>
        </a-col>
      </a-row>
      <div>
        <a-button class="btn">绑定</a-button>
      </div>
    </div>
  </a-modal>
</template>

<script>
import { GE_PREFIX, MSG_DX } from "./server";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      qcodeArr: [],
      phone: '',
      yzSoft: false,
      code: '',
      yzNum: 60,
      time: '',
      qcode: "86,0",
    };
  },
  created() {
    GE_PREFIX().then(res => {
      if (!res) return;
      this.qcodeArr = res.data;
    });
  },
  computed: {

  },
  watch: {

  },
  methods: {
    onYzbtn() {
      if (!this.validate(["phone"])) return;
      this.yzSoft = true;
      this.$nextTick(() => {
        this.time = setInterval(() => {
          if (this.yzNum == 1) {
            clearInterval(this.time);
            this.yzSoft = false;
            this.yzNum = 60;
          }
          this.yzNum--;
        }, 1000);
      });
      MSG_DX({ phone: "+" + this.qcode.split(",")[0] + this.phone }).then(
        res => {
          if (!res) return;
          this.$message.success(res.msg);
        }
      );
    },
    validate(arr) {
      if (arr.includes("phone") && !this.phone) {
        this.$message.error("手机号不能为空！");
        return false;
      }
      if (arr.includes("code") && !this.phone) {
        this.$message.error("验证码不能为空！");
        return false;
      }
      return true;
    },
    close() {
      this.$emit('close')
    }
  }
};
</script>

<style lang="less" scoped>
.tits {
  margin: 10px 0 50px 0;
  font-size: 21px;
  color: #333333;
  .logo {
    width: 162px;
    height: 85px;
  }
}
.tabs {
  width: 320px;
  display: inline-block;
  .forms {
    border-top: 0;
  }
  &/deep/.ant-tabs-bar {
    margin: 0;
    .ant-tabs-nav {
      width: 100%;
      .ant-tabs-tab {
        margin: 0;
        width: 50%;
      }
    }
  }
}
.forms {
  width: 320px;
  border: solid 1px #dadada;
  display: inline-block;
  .fitem {
    height: 46px;
    line-height: 46px;
    border-bottom: solid 1px #dadada;
    &:last-child {
      border: 0;
    }
    div:nth-child(1) {
      margin-right: 10px;
    }
    img {
      width: 68px;
      height: 24px;
    }
    .yzbtn {
      width: 82px;
      height: 30px;
      background-color: #0084ff;
      color: #fff;
      border-color: #fff;
      padding: 0;
    }
    &/deep/.ant-select {
      width: 100%;
      .ant-select-selection {
        border: 0;
      }
    }
  }
  input {
    width: 100%;
    border: 0;
    border-color: #fff;
  }
}
.formT {
  width: 320px;
  height: 46px;
  line-height: 46px;
  border: solid 1px #dadada;
  display: inline-block;
  div:nth-child(1) {
    margin-right: 10px;
  }
  input {
    width: 100%;
    border: 0;
    border-color: #fff;
  }
}
.xy {
  margin: 16px 0;
  padding-right: 44px;
  a {
    color: #999999;
  }
}
.third {
  display: flex;
  padding-bottom: 10px;
  .alipay {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-left: 114px;
    .ali-img {
      width: 16px;
      height: 16px;
      display: flex;
      margin-right: 2px;
      img {
        margin: 0;
      }
    }
    .ali-desc {
      font-size: 12px;
    }
  }
}
.btn {
  width: 320px;
  height: 44px;
  background-color: #0084ff !important;
  color: #fff !important;
  border-color: #fff !important;
  margin-bottom: 12px;
}
.fd {
  button:nth-child(1) {
    color: #0084ff !important;
  }
  button:nth-child(2) {
    color: #999999 !important;
  }
}

</style>